<?php
//	file:  UserApi.class.php
//	time:  Jan 12, 2016 1:53:17 PM

namespace Have\Api;

use Have\Model\UcenterMemberModel;
class UserApi extends Api{
    
    protected function _init(){
        $this->model = new UcenterMemberModel();
        $this->M = M('UcenterMember');
    }
    
    /**
     * 用户登录认证
     * @param string $username  用户名
     * @param string $password  用户密码
     * @param integer $type     用户类型 (1-用户名, 2-邮箱)
     * @return integer 登录成功-用户ID，登录失败-错误编号
     */
    public function login($username, $password, $type = 1) {
        return $this->model->login($username, $password, $type);
    }
    
    public function register($username, $password, $email, $authory, $mobile = '') {
        return $this->model->register($username, $password, $email, $authory, $mobile);
    }
    
    /**
     * 用户退出注销
     */
    public function logout() {
        return $this->model->logout();
    }
    
    public function relogin($uid) {
        return $this->model->relogin($uid);
    }
    
    public function getError() {
        return $this->M->getError();
    }
    
    public function create($data='', $type='') {
        return $this->M->create($data, $type);
    }
    
    public function where($where,$parse=null) {
        return $this->M->where($where, $parse);
    }
    
    public function save($data='',$options=array()) {
        return $this->M->save($data, $options);
    }
    
    /**
     * 更新用户信息
     * @param int $uid 用户id
     * @param string $password 密码，用来验证
     * @param array $data 修改的字段数组
     * @return true 修改成功, false 修改失败
     */
    public function updateInfo($uid, $password, $data) {
        if ($this->model->updateUserFields($uid, $password, $data)) {
            $return['status'] = true;
        } else {
            $return['status'] = false;
            $return['info'] = $this->model->getError();
        }
        return $return;
    }
    
}
	
	
?>